package cn.bonoon.kernel.support.services.handler;

import javax.persistence.EntityManager;

import cn.bonoon.kernel.events.OperateEvent;
import cn.bonoon.kernel.support.entities.Persistable;

/**
 * <pre>
 * 操作符定义的操作
 * 
 * 可以定义某个操作符，再实现这个操作符所对应的具体操作，然后把两者注册到{@link cn.bonoon.kernel.support.services.AbstractOperateService AbstractOperateService}对象里
 * </pre>
 * @author jackson
 *
 */
public interface OperateHandler {
	OperateHandler NULL = new OperateHandler(){

		@Override
		public Object handler(EntityManager entityManager, OperateEvent event, Persistable entity) {
			return entity.getId();
		}

		@Override
		public MultiOperateHandlerExecuter handler(EntityManager entityManager, OperateEvent event) {
			return new MultiOperateHandlerExecuter(){

				@Override
				public MultiOperateHandlerExecuter addParameter(Persistable entity) { return this; }

				@Override
				public void execute() { }
				
			};
		}

	};
	
	/**
	 * <pre>
	 * 执行对一个数据库实体对象进行操作的方法
	 * </pre>
	 * @param entityManager
	 * @param event
	 * @param entity
	 * @return
	 */
	Object handler(EntityManager entityManager, OperateEvent event, Persistable entity);
	
	/**
	 * <pre>
	 * 实现对多个数据库实体对象进行操作的方法
	 * </pre>
	 * @param entityManager
	 * @param event
	 * @return
	 */
	MultiOperateHandlerExecuter handler(EntityManager entityManager, OperateEvent event);
}
